<?php
/* 
 * Copyright (c) 2018-2021   All rights reserved.
 *
 * 创建时间：2021-11-25 00:03:48
 *
 * 项目：/ipban  -  $  - AdminRecordController.php
 *
 * 作者：{{AUTO GENERATE}}
 */

//此文件使用程序自动生成，下次生成时【不会】覆盖。
//在这里可以补充、完善你的程序逻辑

namespace modules\levs\modules\ipban\controllers;

use Lev;
use lev\base\Viewv;
use modules\levs\modules\ipban\controllers\_gen\BaseAdminRecord;
use modules\levs\modules\ipban\ipRecordCacheHelper;
use modules\levs\modules\ipban\table\recordModelHelper;

!defined('INLEV') && exit('Access Denied LEV');

class BaseAdminRecordMiddle extends BaseAdminRecord
{

    public static function actionCensusIp() {
        $date = Lev::stripTags(Lev::GPv('date'));
        $H = Lev::stripTags(Lev::GPv('h'));

        $time = is_numeric($date) ? $date : strtotime($date);
        Lev::showMessages(ipRecordCacheHelper::censusIp($time, is_numeric($H) ? $H : false));
    }

    public static function headerHtm()
    {
        //return parent::headerHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义headerHtm：文件位置：'.__DIR__ . '/AdminRecordController.php'.'</tips>';
        return Viewv::renderPartial(static::$tmpPath . '/myself/headerHtm', [

        ]);
    }

    public static function footerHtm()
    {
        return parent::footerHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义footerHtm</tips>';
    }

    public static function cardFooterButtons($btns = [])
    {
        return parent::cardFooterButtons($btns); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义cardFooterButtons</tips>';
    }

    public static function headerViewHtm()
    {
        return parent::headerViewHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义headerViewHtm：文件位置：'.__DIR__ . '/AdminRecordController.php'.'</tips>';
    }

    public static function footerViewHtm()
    {
        return parent::footerViewHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义footerViewHtm</tips>';
    }

    public static function col_status() {
        return recordModelHelper::statuses();
    }

}

class AdminRecordController extends BaseAdminRecordMiddle
{

    public static $tmpPath = 'admin-record';
    public static $trash   = true;//是否允许删除数据
    public static $addurl  = false;//是否显示创建数据按钮
    public static $addRoute = 'Form_ipban_record';//自定义创建数据表单地址 - 默认使用源表单

    public static $srhtitle    = '用户标识';//模糊搜索字段名称
    public static $srhkeyWhere = "useragent LIKE '#%{srhkey}%'";//模糊搜索sql语句 例：name LIKE '%{srhkey}%'

    public static $limit = 20;//每页显示多少条
    public static $order = ['id DESC'];//排序

    /**
     * 列表显示字段设置
     * 例：array(
    'id'           => array('order' => null, 'name' => 'Id', 'thattr' => 'wd30 nowrap', 'merge' => []),

    'name'         => array('order' => null, 'name' => '模块名称', 'thattr' => 'wd30 nowrap', 'merge' => ['addtime']),

    'displayorder' => array('order' => null, 'name' => '排序', 'thattr' => 'wd30 nowrap', 'merge' => []),

    'uptime'       => array('order' => null, 'name' => '更新时间', 'thattr' => 'wd30 nowrap', 'merge' => []),

    );
     *
     * order: 点击字段排序
     * name: 字段名称
     * thattr: 表格th属性，放class属性内，内容举例：wd30 nowrap" style="font-size:12px
     * merge: 合并显示，多个字段合并显示到一个上
     *
     * @see BaseAdminRecord::showColumns();
     */
    public static function showColumns() {
        //return parent::showColumns(); // TODO: Change the autogenerated stub
        return array(
                //'id'         => array('order' => null, 'name' => 'Id', 'thattr' => 'wd30 nowrap', 'merge' => []),

                'ip'         => array('order' => null, 'name' => 'IP', 'thattr' => 'wd30 nowrap', 'merge' => []),

                'iptotal'    => array('order' => 1, 'name' => 'IP计数', 'thattr' => 'wd30 nowrap', 'merge' => []),

                'pagetotal'  => array('order' => 1, 'name' => 'page计数', 'thattr' => 'wd30 nowrap', 'merge' => []),

                'pagename'   => array('order' => null, 'name' => '页面标识', 'thattr' => 'wd100 nowrap', 'merge' => ['requesturi']),

                //'requesturi' => array('order' => null, 'name' => '请求地址', 'thattr' => ' nowrap', 'merge' => []),

                'referer'    => array('order' => null, 'name' => 'Referer', 'thattr' => ' nowrap', 'merge' => ['useragent']),

                //'useragent'  => array('order' => null, 'name' => '用户标识', 'thattr' => ' nowrap', 'merge' => []),

                //'settings'   => array('order' => null, 'name' => '通用设置', 'thattr' => 'wd30 nowrap', 'merge' => []),

                'status'     => array('order' => null, 'name' => '状态', 'thattr' => 'wd30 nowrap', 'merge' => []),

                'addtime'    => array('order' => 1, 'name' => '添加时间', 'thattr' => 'wd30 nowrap', 'merge' => []),

            );
    }

    /**
     *
     return [
        'showtype' => [
            //从上往下先到先得
            'input_{columnKey}'  => ['width'=>120,'textarea'=>1],//显示为无刷新更改字段
            'srhkey_{columnKey}' => ['or'=>['{columnKey}']],//显示为点击可搜索字段
            'status_{columnKey}' => 1,//显示为开关状态字段 status 自动
            'order_{columnKey}'  => 1,//显示为可排序输入框 含order关键字 自动
            'time_{columnKey}'   => 1,//显示为时间格式字段 含time关键字 自动
        ],
    ];
     *
     * @return array
     */
    public static function setColumnShowtype()
    {
        //return parent::setColumnShowtype(); // TODO: Change the autogenerated stub
        return [
            'showtype' => [
                //从上往下先到先得
                'input_{columnKey}'  => ['width'=>120,'textarea'=>1],//显示为无刷新更改字段
                'srhkey_{columnKey}' => ['or'=>['{columnKey}']],//显示为点击可搜索字段
                'srhkey_ip' => [],//显示为点击可搜索字段
                //'srhkey_requesturi' => [],//显示为点击可搜索字段
                'srhkey_pagename' => [],//显示为点击可搜索字段
                'srhkey_status' => [],//显示为点击可搜索字段
                //'srhkey_referer' => [],//显示为点击可搜索字段
                //'srhkey_useragent' => [],//显示为点击可搜索字段
                'status_{columnKey}' => 1,//显示为开关状态字段 status 自动
                'order_{columnKey}'  => 1,//显示为可排序输入框 含order关键字 自动
                'time_{columnKey}'   => 1,//显示为时间格式字段 含time关键字 自动
            ],
        ];
    }

    public static function formatListsv($sv, $lists)
    {
        $v = $sv;
        $sv = parent::formatListsv($sv, $lists); // TODO: Change the autogenerated stub
        $sv['ip'] && $sv['ip'].= '<p class="scale8 transl buttons-row"><a class="button button-fill button-small" href="'.Lev::toReRoute(['admin-census', 'ip'=>$v['ip']]).'">统计IP</a>
                                    <a class="button-fill button color-gray button-small" target="_blank" _bk="1" href="https://www.baidu.com/baidu?wd='.$v['ip'].'">
                                    查IP
                                    </a></p>';
        return $sv;
    }

    public static function formatUid($sv, $lists, $srhkey = ['uid'])
    {
        return parent::formatUid($sv, $lists, $srhkey); // TODO: Change the autogenerated stub
    }

    public static function redirct($columnKey, $sv)
    {
        return parent::redirct($columnKey, $sv); // TODO: Change the autogenerated stub
    }

    public static function optButtons($sv)
    {
        return parent::optButtons($sv); // TODO: Change the autogenerated stub
    }

    public static function footerBtns($btns = [])
    {
        return parent::footerBtns($btns); // TODO: Change the autogenerated stub
    }

}